<?php
class CityModel
{
	static private $_tableName = 'group_city'; 
	
	static public function getTableName()
	{
		return self::$_tableName;
	}
	
	static public function getAll()
	{
		$result = array();
		$sql = 'SELECT * FROM '.self::getTableName();
		$result = DB::fetchAll($sql);
		return $result;
	}
	
	static public function existName($name_cn)
	{
		$sql = 'SELECT id FROM '.self::getTableName().' WHERE name_cn = :name_cn';
		$data = array('name_cn' => $name_cn);
		$result = DB::fetch($sql, $data);
		return $result;
	}
	
	static public function insert($params)
	{
		$sql = 'INSERT INTO '.self::getTableName() .' (name_cn,name_en,enable) VALUES (:name_cn,:name_en,:enable)';
		$data = array(
			'name_cn' => $params['name_cn'],
			'name_en' => $params['name_en'],
			'enable' => $params['enable'],
		);
		$result = DB::insert($sql, $data);
		return $result;
	}
	
	static public function update($params)
	{
		$sql = 'UPDATE '.self::getTableName() .' SET name_cn = :name_cn,name_en = :name_en,enable = :enable, WHERE city_id = :city_id';
		$data = array(
			'name_cn' => $params['name_cn'], 
			'name_en' => $params['name_en'], 
			'enable' => $params['enable'], 
			'city_id'=>$params['city_id']
		);
		$result = DB::execute($sql, $data);
		return $result;
	}
	
	static public function delete($city_id)
	{
		$sql = 'DELETE FROM '.self::getTableName() .' WHERE city_id = :city_id';
		$data = array('city_id' => $city_id);
		$result = DB::execute($sql, $data);
		return $result;
	}
	
	
}